package com.xy.gateway.cert;

import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

import com.xy.gateway.exception.GateWayException;
import com.xy.gateway.model.Providercert;
import com.xy.gateway.request.pay.handle.RequestParaHandler;

public class CertManagerCCB extends CertManagerAbstrace {
	public static Logger  log= Logger.getLogger(CertManagerCCB.class);

	public boolean verifyResSignData() throws GateWayException {
		String p = req.getParameter("ccbParam");
		String r = null;
	/*	try {
			r = new ECipher_Decode().decode(p);
		} catch (Exception e) {
			log.error("",e);
		}
*/
		return r == null ? false : true;
	}

	@Override
	public String genReqSignData() throws GateWayException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void addReqSignDate(Map<String, String> reqMap)
			throws GateWayException {
		if(paytype.equals("1")){
			addReqSignDate_corperbank(reqMap);
		}else{
			addReqSignDate_perbank(reqMap);
		}
	}
	public void addReqSignDate_corperbank(Map<String, String> reqMap)
	throws GateWayException {

		Vector vName = new Vector();
		Vector vValue = new Vector();
		String prikey = providercert.getEpaypriv();
		reqMap.put("TXCODE", "530500");
		Map<String, String> reqMap1 = requestParaHandler
		.getReqSignParaValuesMap();
		Set<String> s = reqMap1.keySet();
		for (String k : s) {
			vName.add(k);
//		System.out.println("vName.add(\""+k+"\");");
		}
		Collection<String> c = reqMap1.values();
		for (String v : c) {
			vValue.add(v);
//			System.out.println("vValue.add(\""+v+"\");");
		}
		
		String sys_Id="000000000000001";
/*		String ccbParamStr = ECipher_Encode.encode_Rsa(sys_Id, vName,
				vValue, prikey);
		//reqMap.clear();
		
		SimpleDateFormat sftime = new SimpleDateFormat(ECipher_Encode.TIME_PATTERN);
		SimpleDateFormat sfdate = new SimpleDateFormat(ECipher_Encode.DATE_PATTERN);
		String str_Time = sftime.format(new Date());
		String str_Date = sfdate.format(new Date());
		String strPatch ="";
		String strVal ="";
		
		for( int i=0;i<vName.size();i++){
			strPatch+=(String)vName.elementAt(i);
			strVal=(String)vValue.elementAt(i);
			if( strVal!=null ){
				strPatch+="=";
				strPatch+=strVal;
			}
			strPatch+="&";
		}
		
		//原文串中默认加上系统编号
//		strPatch =strPatch +"SYS_TIME="+str_Date+str_Time+"&SYS_ID="+sys_Id+"&SIGN="+ccbParamStr;
		
		reqMap.put("SIGN", ccbParamStr);
		log.debug("ccbParamStr-->"+ccbParamStr);
		log.debug("decode-->"+ECipher_Decode.decode(ccbParamStr));
*/	
	}
	public void addReqSignDate_perbank(Map<String, String> reqMap)
	throws GateWayException {
		Vector vName = new Vector();
		Vector vValue = new Vector();
		String prikey = providercert.getEpaypriv();
		reqMap.put("TXCODE", "530500");
		Map<String, String> reqMap1 = requestParaHandler
		.getReqSignParaValuesMap();
		Set<String> s = reqMap1.keySet();
		for (String k : s) {
			vName.add(k);
//		log.debug("vName.add(\""+k+"\");");
		}
		Collection<String> c = reqMap1.values();
		for (String v : c) {
			vValue.add(v);
//			log.debug("vValue.add(\""+v+"\");");
		}
/*		String ccbParamStr = ECipher_Encode.encode_Rsa_Des("000000000000001", vName,
				vValue, prikey);
		reqMap.clear();
		reqMap.put("ccbParam", ccbParamStr);
		log.debug("ccbParamStr-->"+ccbParamStr);
		log.debug("decode-->"+ECipher_Decode.decode(ccbParamStr));
*/	}

	public CertManagerCCB(Providercert providercert, String sid,
			RequestParaHandler requestParaHandler, HttpServletRequest req,
			String paytype, String reqtype) {
		super(providercert, sid, requestParaHandler, req, paytype, reqtype);
	}

}
